import { createRouter, createWebHistory } from "vue-router";

const options = {
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      name: "root",
      component: () => import("@/components/Home.vue"),
      meta: { title: "首页" },
    },
    {
      path: "/basic",
      name: "basic",
      component: () => import("@/components/Basic.vue"),
      meta: { title: "Basic" },
    },
    {
      path: "/animal",
      name: "animal",
      component: () => import("@/components/Animal.vue"),
      meta: { title: "Animal" },
    },
    {
      path: "/longan",
      name: "longan",
      component: () => import("@/components/Longan.vue"),
      meta: { title: "桂圆" },
    },
    {
      path: "/litchi",
      name: "litchi",
      component: () => import("@/components/Litchi.vue"),
      meta: { title: "荔枝" },
    },
    {
      path: "/full/name",
      name: "fullName",
      component: () => import("@/responsives/FullName.vue"),
      meta: { title: "全名" },
    },
    {
      path: "/user/register",
      name: "userRegister",
      component: () => import("@/responsives/UserRegister.vue"),
      meta: { title: "用户注册" },
    },
    {
      path: "/user/login",
      name: "userLogin",
      component: () => import("@/responsives/UserLogin.vue"),
      meta: { title: "用户登录" },
    },
    {
      path: "/rose",
      name: "rose",
      component: () => import("@/responsives/Rose.vue"),
      meta: { title: "玫瑰" },
    },
    {
      path: "/course/:id",
      name: "course",
      component: () => import("@/responsives/Course.vue"),
      meta: { title: "课程" },
    },
  ],
};

const router = createRouter(options);

// 全局后置钩子
router.afterEach((to) => {
  document.title = to.meta.title;
});

export default router;
